package com.hhit.collaborative_learning.management;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql;
import com.hhit.collaborative_learning.utils.Utils;
import com.mysql.jdbc.StringUtils;
@MultipartConfig
public class UpdateInfoServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userNickName=request.getParameter("userNickName");
		Part file=request.getPart("file");
		String userBrief=request.getParameter("userBrief");
		if(StringUtils.isNullOrEmpty(userBrief)) userBrief="";
		String userId=Utils.getCookieValue("userId", request);
		String fileName="";
		if(file!=null&&file.getSize()>0&&!StringUtils.isNullOrEmpty(file.getName())){
			String path = getServletContext().getRealPath("/userIcons");
			fileName=Utils.saveImage(path, file);
		}
		PublicDaoImplMySql dao=new PublicDaoImplMySql();
		response.getWriter().print(dao.updateInfo(userNickName, userBrief, Integer.parseInt(userId), fileName));
	}

}
